package com.ss.web.tagmark.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.ss.web.tagmark.entity.Annotation;

public interface AnnotationDao extends BaseRepository<Annotation, Long> {

	default Page<Annotation> findByPage(Annotation tag, Pageable page, EntityManager em) {
		String sql = "SELECT * FROM  `annotation` t WHERE 1=1 ";
		Map<String, Object> params = new HashMap<>();
		if (tag.getArticleId() != null) {
			sql += " and article_id = :articleId";
			params.put("articleId", tag.getArticleId());
		}
		if (tag.getOperId() != null) {
			sql += " and oper_id = :operid";
			params.put("operid", tag.getOperId());
		}
		return doQuery(page, sql, Annotation.class, params, em);
	}

	List<Annotation> findByArticleIdAndOperId(Long articleId, Long userId);

	boolean existsBySegmentAndOffsetAndOperId(String segment, Integer offset, Long userId);

}
